﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Profile;

namespace PBDesk.Web.CMS.usercontrols.PBDesk.Membership
{
    public partial class TestCtl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            MembershipCreateStatus status;
            System.Web.Security.MembershipUser user =  System.Web.Security.Membership.CreateUser(TextBox1.Text, "Asdf123#", TextBox1.Text, null, null, true, out status);
            Literal1.Text += "~" + status.ToString();

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser(TextBox2.Text);
            if (user != null)
                Literal1.Text += "~" + user.Email + "~" + user.ProviderUserKey.ToString();
            else
                Literal1.Text += "~" + "No User";
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser(TextBox2.Text);
            if (user != null)
            {
                var profile = ProfileBase.Create(user.UserName, true);
                if (profile != null)
                {
                    profile["firstName"] = TextBox3.Text;
                    profile["lastName"] = TextBox4.Text;
                    profile.Save();
                    Literal1.Text = "Profile Save code executed";
                }
                else
                {
                    Literal1.Text = "Profile object is null";
                }
            }
            else
            {
                Literal1.Text = "null user. profile not created";
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser(TextBox2.Text);
            if (user != null)
            {
                var profile = ProfileBase.Create(user.UserName, true);
                if (profile != null)
                {
                    TextBox5.Text = profile["firstName"].ToString();
                    TextBox6.Text = profile["lastName"].ToString();
                    Literal1.Text = "Profile retrived";
                }
                else
                {
                    Literal1.Text = "Profile object is null";
                }
            }
            else
            {
                Literal1.Text = "null user. profile cannot retrived";
            }
        }
    }
}